<style>
    .layui-table-col-special .layui-table-cell {
        height: auto;
        overflow: visible;
        text-overflow: inherit;
        white-space: normal;
    }
</style>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">人员姓名</label>
                    <div class="layui-input-block">
                        <input type="text" name="admin_name" id="admin_name" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">日志类别</label>
                    <div class="layui-input-block">
                        <select name="journal_type_id" id="journal_type_id" lay-filter="journal_type_id" lay-search="">
                            <option value="">请选择日志类别</option>
                            {foreach $journal_type as $key=>$vo}
                            <option value="{$vo.id}">{$vo.name}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
<!--                <div class="layui-inline">-->
<!--                    <label class="layui-form-label">日期范围</label>-->
<!--                    <div class="layui-input-block">-->
<!--                        <input type="text" name="week_time" id="week_time" placeholder="请输入" autocomplete="off" class="layui-input">-->
<!--                    </div>-->
<!--                </div>-->
                <div class="layui-inline">
                    <label class="layui-form-label">日志等级</label>
                    <div class="layui-input-block">
                        <select name="journal_level_id" id="level_id" lay-search="">
                            <option value="">请选择日志等级</option>
                            {foreach $journal_level as $key=>$vo}
                            <option value="{$vo.id}">{$vo.name}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">日志状态</label>
                    <div class="layui-input-block">
                        <select name="status" id="status" lay-search="">
                            <option value="">请选择日志状态</option>
                            <option value="2">已完成</option>
                            <option value="1">流程中</option>
                            <option value="-1">草稿中</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-admin layui-btn-sm" lay-submit lay-filter="LAY-user-back-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <div style="padding-bottom: 10px;">
                <button class="layui-btn layuiadmin-btn-admin layui-btn-sm" title="刷新" data-type="refresh"><i
                        class="layui-icon layui-icon-refresh-3"></i>
                </button>
                <button class="layui-btn layuiadmin-btn-admin layui-btn-sm {$auth->check('journal/add')?$auth->check('journal/add'):'hide'}"
                        title="添加" data-type="add"><i
                        class="layui-icon layui-icon-add-1"></i>添加
                </button>
                <button class="layui-btn layuiadmin-btn-admin layui-btn-sm {$auth->check('journal/del')?$auth->check('journal/del'):'hide'}"
                        title="删除" data-type="batchdel"><i
                        class="layui-icon layui-icon-delete"></i>删除
                </button>
            </div>
            <table id="LAY-user-back-manage" lay-filter="LAY-user-back-manage"></table>

            <script type="text/html" id="table-useradmin-admin">
                {{#  if(d.edit_auth == '1' && d.status < 2){ }}
                <a class="layui-btn layui-btn-normal layui-btn-xs {$auth->check('journal/edit')?$auth->check('journal/edit'):'hide'}"
                   lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs {$auth->check('journal/del')?$auth->check('journal/del'):'hide'}"
                   lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
                {{#  } else { }}
                <a class="layui-btn layui-btn-normal layui-btn-xs {$auth->check('journal/detail')?$auth->check('journal/detail'):'hide'}"
                   lay-event="detail"><i class="iconfont icon-shenhe6"></i>查看</a>
                <a class="layui-btn layui-btn-normal layui-btn-xs {$auth->check('Common/flowchart')?$auth->check('Common/flowchart'):'hide'}"
                   lay-event="flowchart"><i class="iconfont icon-shenhe6"></i>查看流程图</a>
                {{#  } }}
<!--                {{#  if(d.status == '2'  && d.task_status >= 2){ }}-->
<!--                <a class="layui-btn layui-btn-normal layui-btn-xs {$auth->check('journal/detail')?$auth->check('journal/detail'):'hide'}"-->
<!--                   lay-event="detail"><i class="iconfont icon-shenhe6"></i>查看</a>-->
<!--                <a class="layui-btn layui-btn-normal layui-btn-xs {$auth->check('Common/flowchart')?$auth->check('Common/flowchart'):'hide'}"-->
<!--                   lay-event="flowchart"><i class="iconfont icon-shenhe6"></i>查看流程图</a>-->
<!--                {{#  } else if(d.status == '1' && d.task_status >= 2) { }}-->
<!--                <a class="layui-btn layui-btn-normal layui-btn-xs {$auth->check('journal/detail')?$auth->check('journal/detail'):'hide'}"-->
<!--                   lay-event="detail"><i class="iconfont icon-shenhe6"></i>查看</a>-->
<!--                <a class="layui-btn layui-btn-normal layui-btn-xs {$auth->check('Common/flowchart')?$auth->check('Common/flowchart'):'hide'}"-->
<!--                   lay-event="flowchart"><i class="iconfont icon-shenhe6"></i>查看流程图</a>-->
<!--                {{#  } else if(d.edit_auth == '1') { }}-->
<!--                <a class="layui-btn layui-btn-normal layui-btn-xs {$auth->check('journal/edit')?$auth->check('journal/edit'):'hide'}"-->
<!--                   lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>-->
<!--                <a class="layui-btn layui-btn-danger layui-btn-xs {$auth->check('journal/del')?$auth->check('journal/del'):'hide'}"-->
<!--                   lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>-->
<!--                {{#  } else { }}-->
<!--                <a class="layui-btn layui-btn-normal layui-btn-xs {$auth->check('journal/detail')?$auth->check('journal/detail'):'hide'}"-->
<!--                   lay-event="detail"><i class="iconfont icon-shenhe6"></i>查看</a>-->
<!--                <a class="layui-btn layui-btn-normal layui-btn-xs {$auth->check('Common/flowchart')?$auth->check('Common/flowchart'):'hide'}"-->
<!--                   lay-event="flowchart"><i class="iconfont icon-shenhe6"></i>查看流程图</a>-->
<!--                {{#  } }}-->
            </script>
        </div>
    </div>
</div>
<script src="/static/layuiadmin/layui/layui.js"></script>
<script>
    var listUrl = "{:url('journal/index')}", create = "{:url('journal/add')}", edit = "{:url('journal/edit')}",
        deleteUrl = "{:url('journal/del')}", approval = "{:url('journal/approval')}", grade = "{:url('journal/grade')}",
        detail = "{:url('journal/detail')}", flowchart = "{:url('Common/flowchart')}";
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'soulTable'], function () {
        var $ = layui.$
            , form = layui.form
            , table = layui.table, soulTable = layui.soulTable;

        table.render({
            elem: "#LAY-user-back-manage", url: listUrl
            ,cellMinWidth: 120 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            , overflow: {
                type: 'tips'
                // ,hoverTime: 500 // 悬停时间，单位ms, 悬停 hoverTime 后才会显示，默认为 0
                , color: 'white' // 字体颜色
                , bgColor: '#009688' // 背景色
            }
            ,size:"sm"
            , cols: [
                [
                    {type: "checkbox", fixed: "left"},
                    {field: "journal_no",   align: "center", title: "日志编号",event:"SignCheck"},
                    {field: "admin_name", align: "center", title: "人员名称"},
                    {
                        field: "journal_level_id",  align: "center", title: "日志等级", templet: function (e) {
                            if (e.JournaLevel != null) {
                                return e.JournaLevel.name;
                            } else {
                                return "Unknown";
                            }
                        }
                    },
                    {field: "is_week",  align: "center", title: "具体时间"},
                    {field: "week_time", align: "center", width:200, title: "周起止日期"},
                    {field: "group_name",  align: "center", title: "所属部门"},
                    {field: "create_time",  align: "center", title: "填写日期"},
                    {
                        field: "status", align: "center", title: "状态", templet: function (e) {
                            if (e.status === 1) {
                                return "<span class=\"text-success\"><i class=\"layui-icon layui-icon-face-smile\" style=\"font-size: 12px; color: #009688;\">&nbsp;已提交</i>";
                            } else if (e.status === 2) {
                                return "<span class=\"text-success\"><i class=\"layui-icon layui-icon-face-smile\" style=\"font-size: 12px; color: #009688;\">&nbsp;已审核</i>";
                            } else {
                                return "<span class=\"text-success\"><i class=\"layui-icon layui-icon-face-cry\" style=\"font-size: 12px;\">&nbsp;存入草稿箱</i>";
                            }
                        }
                    },
                    {title: "操作",  align: "center", width:200,  fixed: "right", toolbar: "#table-useradmin-admin"}]],
            response: {
                statusCode: 200 //重新规定成功的状态码为 200，table 组件默认为 0
            }, done: function (e) {
                soulTable.render(this);
                var id = $('#id').val();
                // e.data.forEach(function (element) {
                //     if (id != element.admin_id) {
                //         $(".layui-table").find("[data-field='status']").css("display","none");
                //     }
                // });

            },
            parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.code,
                    "count": res.total, //解析数据长度
                    "data": res.data, //解析数据列表
                };

            },
            text: {
                none: '呀！一条数据都没有'
            },

            page: true,
            limit: 10,
        });
        //按钮触发
        table.on("tool(LAY-user-back-manage)", function (e) {
            var param = $.param({'id': e.data.id});
            if ("edit" === e.event) {
                layer.open({
                    type: 2
                    , skin: 'layui-layer-molv'
                    , title: '编辑'
                    , content: edit + '?' + param
                    , area: ['100%', '100%']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        var iframeWindow = window['layui-layer-iframe' + index]
                            , submitID = 'LAY-user-back-submit'
                            , submit = layero.find('iframe').contents().find('#' + submitID);
                        //监听提交
                        iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                            var field = data.field; //获取提交的字段
                            //提交 Ajax 成功后，静态更新表格中的数据
                            if (field.flow_id == ""){
                                layer.msg("请选择工作流");
                                return false;
                            }
                            if (field.journal_type_id == ""){
                                layer.msg("请选择日志类别");
                                return false;
                            }
                            $.ajax({
                                url: edit + '?' + param,
                                type: 'post',
                                data: field,
                                beforeSend: function () {
                                    var DISABLED = 'layui-btn-disabled';
                                    // 增加样式
                                    $('.layui-layer-btn0').addClass(DISABLED);
                                    // 增加属性
                                    $('.layui-layer-btn0').attr('disabled', 'disabled');
                                    layer.load(2, {
                                        shade: [0.6, '#fff'], content: '数据更新中...', success: function (layero) {
                                            layero.find('.layui-layer-content').css({
                                                'padding-top': '6px',
                                                'width': '150px',
                                                'padding-left': '40px'
                                            });
                                            layero.find('.layui-layer-ico16, .layui-layer-loading .layui-layer-loading2').css({
                                                'width': '150px !important',
                                                'background-position': '2px 0 !important'
                                            });
                                        }
                                    });
                                },
                                success: function (res) {
                                    var DISABLED = 'layui-btn-disabled';
                                    if (res.code === 200) {
                                        layer.msg(res.msg, {icon: 1});
                                        table.reload('LAY-user-back-manage');
                                        layer.closeAll(); //关闭弹层
                                        $('.layui-layer-btn0').removeClass(DISABLED);
                                        $('.layui-layer-btn0').removeAttr('disabled');
                                    } else {
                                        $('.layui-layer-btn0').removeClass(DISABLED);
                                        $('.layui-layer-btn0').removeAttr('disabled');
                                        layer.closeAll(); //关闭弹层
                                        layer.msg(res.msg, {icon: 5});
                                        return false;
                                    }
                                }
                            });
                        });
                        submit.trigger('click');
                    }
                });
            } else if ("del" === e.event) {
                var params = $.param({'ids': e.data.id});
                layer.confirm("确定删除此日志吗？", function (t) {
                    $.ajax({
                        url: deleteUrl + '?' + params, success: function (res) {
                            if (res.code === 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('LAY-user-back-manage');
                                layer.close(index); //关闭弹层
                            } else {

                                layer.msg(res.msg, {icon: 5});
                                return false;
                            }
                        }
                    });
                })
            } else if ("approval" === e.event) {
                layer.open({
                    type: 2
                    , skin: 'layui-layer-molv'
                    , title: '审核'
                    , content: approval + '?' + param
                    , area: ['100%', '100%']
                    , maxmin: true
                    , btn: ['审核', '取消']
                    , yes: function (index, layero) {
                        var iframeWindow = window['layui-layer-iframe' + index]
                            , submitID = 'LAY-user-back-submit'
                            , submit = layero.find('iframe').contents().find('#' + submitID);
                        //监听提交
                        iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                            var field = data.field; //获取提交的字段
                            //提交 Ajax 成功后，静态更新表格中的数据
                            layer.open({
                                type: 2
                                , skin: 'layui-layer-molv'
                                , title: '评等级'
                                , content: grade + '?' + param
                                , area: ['100%', '100%']
                                , maxmin: true
                            });
                            layer.close(index); //关闭弹层
                            // $.ajax({
                            //     url: approval + '?' + param,
                            //     type: 'post',
                            //     data: field,
                            //     success: function (res) {
                            //         if (res.code === 200) {
                            //             layer.msg(res.msg, {icon: 1});
                            //             table.reload('LAY-user-back-manage');
                            //             layer.close(index); //关闭弹层
                            //         } else {
                            //
                            //             layer.msg(res.msg, {icon: 5});
                            //             return false;
                            //         }
                            //     }
                            // });
                        });
                        submit.trigger('click');
                    }
                });
            } else if ("detail" === e.event) {
                layer.open({
                    type: 2
                    , skin: 'layui-layer-molv'
                    , title: '查看'
                    , content: detail + '?' + param
                    , area: ['100%', '100%']
                });
            }else if ("flowchart" == e.event) {
                var params = $.param({'id': e.data.id, 'table': 'journals'});
                layer.open({
                    type: 2
                    , skin: 'layui-layer-molv'
                    , title: '查看流程图'
                    , content: flowchart + '?' + params
                    , area: ['100%', '100%']
                    , maxmin: true
                });
            }else if ("SignCheck" == e.event){
                top.layui.index.openTabsPage(detail + '?' + param, "日志信息");  //完成页面跳转
                // layer.open({
                //     type: 2,
                //     id: 'top_' +  e.data.id,
                //     shade: false,
                //     area: ['100%', '100%'],
                //     content: detail + '?' + param
                // });
            }
        });





        //监听搜索
        form.on('submit(LAY-user-back-search)', function (data) {
            var field = data.field;
            //执行重载
            table.reload('LAY-user-back-manage', {
                where: field
            });
        });
        //事件
        var active = {
            batchdel: function () {
                var checkStatus = table.checkStatus('LAY-user-back-manage')
                    , checkData = checkStatus.data; //得到选中的数据
                if (checkData.length === 0) {
                    return layer.msg('请选择数据');
                }
                var id = ''; //task_id
                for (var i = 0; i < checkData.length; i++) {
                    id += checkData[i].id + ",";
                }
                id = id.substring(0, id.length - 1);
                var ids = $.param({'ids': id});
                layer.confirm('确定删除吗？', function (index) {
                    //执行 Ajax 后重载
                    $.ajax({
                        url: deleteUrl,
                        type: "post",
                        data: ids,
                        success: function (res) {
                            if (res.code === 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('LAY-user-back-manage');
                                layer.close(index); //关闭弹层
                            } else {

                                layer.msg(res.msg, {icon: 5});
                                return false;
                            }
                        }
                    });
                    // table.reload('LAY-user-back-manage');
                    // layer.msg('已删除');
                });
            }
            , add: function () {
                layer.open({
                    type: 2
                    , skin: 'layui-layer-molv'
                    , title: '添加'
                    , content: create
                    , area: ['100%', '100%']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        var iframeWindow = window['layui-layer-iframe' + index]
                            , submitID = 'LAY-user-back-submit'
                            , submit = layero.find('iframe').contents().find('#' + submitID);
                        //监听提交
                        iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {

                            var field = data.field; //获取提交的字段
                            if (field.flow_id == ""){
                                layer.msg("请选择工作流");
                                return false;
                            }
                            if (field.journal_type_id == ""){
                                layer.msg("请选择日志类别");
                                return false;
                            }
                            //提交 Ajax 成功后，静态更新表格中的数据
                            $.ajax({
                                url: create,
                                type: 'post',
                                data: field,
                                beforeSend: function () {
                                    var DISABLED = 'layui-btn-disabled';
                                    // 增加样式
                                    $('.layui-layer-btn0').addClass(DISABLED);
                                    // 增加属性
                                    $('.layui-layer-btn0').attr('disabled', 'disabled');
                                    layer.load(2, {
                                        shade: [0.6, '#fff'], content: '数据新增中...', success: function (layero) {
                                            layero.find('.layui-layer-content').css({
                                                'padding-top': '6px',
                                                'width': '150px',
                                                'padding-left': '40px'
                                            });
                                            layero.find('.layui-layer-ico16, .layui-layer-loading .layui-layer-loading2').css({
                                                'width': '150px !important',
                                                'background-position': '2px 0 !important'
                                            });
                                        }
                                    });
                                },
                                success: function (res) {
                                    var DISABLED = 'layui-btn-disabled';
                                    if (res.code === 200) {
                                        layer.msg(res.msg, {icon: 1});
                                        table.reload('LAY-user-back-manage');
                                        layer.closeAll(); //关闭弹层
                                        $('.layui-layer-btn0').removeClass(DISABLED);
                                        $('.layui-layer-btn0').removeAttr('disabled');
                                    } else {
                                        $('.layui-layer-btn0').removeClass(DISABLED);
                                        $('.layui-layer-btn0').removeAttr('disabled');
                                        layer.msg(res.msg, {icon: 5});
                                        return false;
                                    }
                                }
                            });
                        });
                        submit.trigger('click');
                    }
                });
            }, refresh: function () {
                table.reload('LAY-user-back-manage');
            },
            tongbu: function () {
                layer.open({
                    type: 2
                    , skin: 'layui-layer-molv'
                    , title: '同步数据'
                    , content: synchronization
                    , area: ['80%', '80%']
                    , maxmin: true
                })
            }
        };
        $('.layui-btn.layuiadmin-btn-admin').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
